<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增课程包')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-package-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">课程包名称：</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">类型：</label>
            <div class="col-sm-8" th:with="type=${@dict.getType('course_package_type')}">
                <label class="check-box" th:each="dict : ${type}">
                    <input name="typeName" type="checkbox"  th:text="${dict.dictLabel}"
                           th:value="${dict.dictValue}" >
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">排序：</label>
            <div class="col-sm-8">
                <input name="orderNum" class="form-control" type="text">
            </div>
        </div>
        <!--        <div class="form-group">-->
        <!--            <label class="col-sm-3 control-label">促销信息：</label>-->
        <!--            <div class="col-sm-8">-->
        <!--                <input name="promoInfo" class="form-control" type="text">-->
        <!--            </div>-->
        <!--        </div>-->
        <!--        <div class="form-group">-->
        <!--            <label class="col-sm-3 control-label">价格：</label>-->
        <!--            <div class="col-sm-8">-->
        <!--                <input name="price" class="form-control" type="text">-->
        <!--            </div>-->
        <!--        </div>-->
        <!--        <div class="form-group">-->
        <!--            <label class="col-sm-3 control-label">原价：</label>-->
        <!--            <div class="col-sm-8">-->
        <!--                <input name="originPrice" class="form-control" type="text">-->
        <!--            </div>-->
        <!--        </div>-->
        <!--        <div class="form-group">-->
        <!--            <label class="col-sm-3 control-label">目标用户：</label>-->
        <!--            <div class="col-sm-8">-->
        <!--                <input name="targetUser" class="form-control" type="text">-->
        <!--            </div>-->
        <!--        </div>-->
        <!--        <div class="form-group">-->
        <!--            <label class="col-sm-3 control-label">维度：</label>-->
        <!--            <div class="col-sm-8">-->
        <!--                <input name="dimensions" class="form-control" type="text">-->
        <!--            </div>-->
        <!--        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">标签：</label>
            <div class="col-sm-8">
                <input name="tags" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">月龄 低限：</label>
            <div class="col-sm-8">
                <input name="ageLow" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">月龄 高限：</label>
            <div class="col-sm-8">
                <input name="ageHigh" class="form-control" type="text">
            </div>
        </div>
        <!--        <div class="form-group">-->
        <!--            <label class="col-sm-3 control-label">日期前有效：</label>-->
        <!--            <div class="col-sm-8">-->
        <!--                <div class="input-group date">-->
        <!--                    <input name="avaliableDate" class="form-control" placeholder="yyyy-MM-dd" type="text">-->
        <!--                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
        <!--                </div>-->
        <!--            </div>-->
        <!--        </div>-->
        <!--        <div class="form-group">-->
        <!--            <label class="col-sm-3 control-label">厂商名字：</label>-->
        <!--            <div class="col-sm-8">-->
        <!--                <input name="vendorName" class="form-control" type="text">-->
        <!--            </div>-->
        <!--        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label"></label>
            <div class="col-sm-8">

                <a class="btn btn-success" onclick="onFile()">
                    <i class="fa fa-plus"></i> 上传封面
                </a>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">封面路径：</label>
            <div class="col-sm-8">
                <input name="cover" id="cover" class="form-control" type="text">
            </div>
        </div>
        <input type="file" name="upload" id="upload" style="display: none;"/>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    var prefix = ctx + "system/package"
    $("#form-package-add").validate({
        focusCleanup: true
    });
    var time = 0;
    function submitHandler() {
        if (time==0){
            if ($.validate.form()) {
                time = 1;
                $.operate.save(prefix + "/add", $('#form-package-add').serialize());
            }
        }


    }

    $("input[name='created']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='avaliableDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='lastUpdated']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    function onFile() {
        $('#upload').click();
    }

    $('#upload').on('change', function () {
        var farmdate = new FormData();
        farmdate.append("file", $('#upload')[0].files[0]);
        $.ajax({
            type: "post",
            url: "/system/courseContent/importImg",
            data: farmdate,
            contentType: false,
            processData: false,
            success: function (date) {
                $('#cover').val(date);
            }
        })
    });
</script>
</body>
</html>